﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using GEAR_Structure;

namespace Gear_Base
{
    public partial class Main : Form
    {
        private Project project;
        private string projectfolder = null;
        public Main()
        {
            InitializeComponent();
            ApplicationInfo.materialPath = AppDomain.CurrentDomain.BaseDirectory + @"\Data\Archiviomateriali.xml";
            this.project = new Project();
            //this.project = this.project.load(AppDomain.CurrentDomain.BaseDirectory  + @"\Data\ArchivioStr.xml");
        }

        private void smi_material_Click(object sender, EventArgs e)
        {
            MaterialForm frm = new MaterialForm(this.project);
            frm.MdiParent = this;
            frm.Show();
        }

        private void smi_save_Click(object sender, EventArgs e)
        {

        }

        private void struttureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayerForm frm = new LayerForm(this.project);
            frm.MdiParent = this;
            frm.Show();
        }

        private void mainMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void fileToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void affiancaVerticalmenteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void affiancaInOrizzontaleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SplashProject sp = new SplashProject(this);
            sp.MdiParent = this;
            sp.Show();
        }

        private void importaDatiClimaticiToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Gear_Base.CimateDataView cdw = new CimateDataView();
            cdw.ShowDialog();
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (projectfolder != null)
                this.project.save(projectfolder);
            else
            {
                string guid = Guid.NewGuid().ToString();
                Directory.CreateDirectory(Configuration.getInstance().ProjectLocation+"\\"+guid);
                this.project.save(Configuration.getInstance().ProjectLocation + "\\" + guid);
            }

        }

        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    this.project.save();
            //}
            //catch
            //{
            //    SaveFileDialog sfd = new SaveFileDialog();
            //    sfd.Filter = "XML File(*.xml)|*.xml";
            //    if (DialogResult.OK == sfd.ShowDialog())
            //        this.project.export(sfd.FileName);
            //}
        }

        public void load(string directoryPath)
        {
            this.project = this.project.loadDirectory(directoryPath);
            projectfolder = directoryPath;
        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.project = new Project();
            projectfolder = null;
        }
    }
}
